from datetime import datetime
from typing import Optional
# import pytz


from sqlmodel import SQLModel
from fastapi_amis_admin.models import Field
from ..common import AppBaseModel, PageParams


# tz = pytz.timezone('Asia/Shanghai')
# Create your models here.
class SysDept(AppBaseModel, table=True):
    __tablename__ = 'sys_dept'
    __table_args__ = {'extend_existing': True}
    pid: Optional[int] = Field(default=0, index=True, title='上级ID', nullable=True)
    pids: Optional[str] = Field(default='', title='所有上级ID，用逗号分开', nullable=True)
    name: Optional[str] = Field(nullable=False, title='名称')
    short_name: Optional[str] = Field(title='简称',
                                      serialization_alias="shortName",
                                      validation_alias="shortName",
                                      alias="shortName")
    code: Optional[str] = Field(title='编码')
    app_code: Optional[str] = Field(title='所属系统编码',
                                      alias="appCode",
                                      serialization_alias="appCode",
                                      validation_alias="appCode")
    sort: Optional[int] = Field(default=0, index=True, title='排序')
    region_names: Optional[str] = Field(default='', title='所属区域名称,用逗号隔开', nullable=True,
                                        serialization_alias="regionNames",
                                        validation_alias="regionNames",
                                        alias="regionNames")
    region_ids: Optional[str] = Field(default='', title='所属区域id,用逗号隔开', nullable=True,
                                      alias="regionIds",
                                      serialization_alias="regionIds",
                                      validation_alias="regionIds")



class UserDept(SQLModel, table=True):
    __tablename__ = 'sys_user_dept'
    __table_args__ = {'extend_existing': True}
    id: Optional[int] = Field(primary_key=True, title='id')
    user_id: Optional[int] = Field(nullable=False, title='用户id')
    dept_id: Optional[int] = Field(nullable=False, title='部门id')
    creator: Optional[int] = Field(title='创建者')
    create_date: Optional[datetime] = Field(title='创建时间')


class DeptQueryParams(PageParams):
    name: Optional[str] = Field(title="名称")